import React, { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import { List } from "react-vant";
import { queryComments } from "../../api/doctor";
import DoctorCommentCard from "../../components/DoctorCommentCard";

export default function Comments() {
  const { id } = useParams();
  const [finished, setFinished] = useState(false);
  const [list, setList] = useState([]);
  const getList = async () => {
    queryComments({ doctorId: id, page: 1, count: 10 }).then((res: any) => {
      console.log(res);
      if (res.result.length < 10) {
        setFinished(true);
      }
      setList(list.concat(res.result));
    });
  };
  useEffect(() => {
    // getList()
  }, []);
  return (
    <div>
      <List
        finished={finished}
        errorText="请求失败，z点击重新加载"
        onLoad={getList}
      >
        {list.map((item: any, index) => {
          return <DoctorCommentCard key={index} data={item} />;
        })}
      </List>
    </div>
  );
}
